/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        rw_lock_generic.h
// Purpose:
// Author:      syy
// Modified by:
// Created:     2014/1/3 15:42
// RCS-ID:
// Licence:
/////////////////////////////////////////////////////////////////////////////
#ifndef PR_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_GENERIC_H_
#define PR_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_GENERIC_H_

#include "../typedefs.h"
#include "rw_lock_wrapper.h"

namespace qb {

class CriticalSectionWrapper;
class ConditionVariableWrapper;

class RWLockGeneric : public RWLockWrapper {
 public:
  RWLockGeneric();
  virtual ~RWLockGeneric();

  virtual void AcquireLockExclusive() OVERRIDE;
  virtual void ReleaseLockExclusive() OVERRIDE;

  virtual void AcquireLockShared() OVERRIDE;
  virtual void ReleaseLockShared() OVERRIDE;

 private:
  CriticalSectionWrapper* critical_section_;
  ConditionVariableWrapper* read_condition_;
  ConditionVariableWrapper* write_condition_;

  int readers_active_;
  bool writer_active_;
  int readers_waiting_;
  int writers_waiting_;
};

}  // namespace qb

#endif  // PR_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_GENERIC_H_
